package com.evon.yardmanagement.ui.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;


import com.evon.yardmanagement.model.ParkingSlot;
import com.evon.yardmanagement.model.Section;
import com.evon.yardmanagement.model.Yard;
import com.evon.yardmanagement.service.ParkingSlotsService;
import com.evon.yardmanagement.transformer.ParkingSlotTransfer;
import com.evon.yardmanagement.ui.dto.ParkingSlotDTO;
import com.evon.yardmanagement.ui.dto.SectionDTO;
import com.evon.yardmanagement.ui.dto.YardDTO;
import com.opensymphony.xwork2.ActionSupport;

public class ParkingSlotAction extends ActionSupport implements ServletRequestAware ,ServletResponseAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
private String req;


	 public String getReq() {
	return req;
}

public void setReq(String req) {
	this.req = req;
}

	private HttpServletRequest request;
	  private HttpServletResponse response;
	  
	/*private Integer slotNumber;
	private String slotName;
	private Integer priority;
	private boolean occupied;
	
	
	
	public Integer getSlotNumber() {
		return slotNumber;
	}



	public void setSlotNumber(Integer slotNumber) {
		this.slotNumber = slotNumber;
	}



	public String getSlotName() {
		return slotName;
	}



	public void setSlotName(String slotName) {
		this.slotName = slotName;
	}



	public Integer getPriority() {
		return priority;
	}



	public void setPriority(Integer priority) {
		this.priority = priority;
	}



	public boolean getOccupied() {
		return occupied;
	}



	public void setOccupied(boolean occupied) {
		this.occupied = occupied;
	}
*/
	
	public ParkingSlotDTO availableParkSlots;

	public ParkingSlotDTO getAvailableParkSlots() {
		return availableParkSlots;
	}

	public void setAvailableParkSlots(ParkingSlotDTO availableParkSlots) {
		this.availableParkSlots = availableParkSlots;
	}
	
	public ParkingSlotAction(){
		this.availableParkSlots = new ParkingSlotDTO();

	}
	public String init(){
		this.availableParkSlots = new ParkingSlotDTO();
		System.out.println(request.getParameter("test-name"));
		return SUCCESS;
	}

	public HttpServletRequest getServletRequest(){
		  return request;
		  }

		  



	public String execute() throws Exception {
		
		request.setAttribute("test", "test1");
		
		//ParkingSlotDTO parkingSlotDTO = new ParkingSlotDTO();
		/*parkingSlotDTO.setOccupied(getOccupied()?"1":"0");
		parkingSlotDTO.setPriority(getPriority());*/
		SectionDTO section = new SectionDTO();
		section.setSectionId(11);
		section.setSectionName("S1");
		YardDTO yard = new YardDTO();
		yard.setId(12);
		yard.setName("Y1");
		section.setYardDTO(yard);
		availableParkSlots.setSection(section);
		/*parkingSlotDTO.setSlotName(getSlotName());
		parkingSlotDTO.setSlotNumber(getSlotNumber());*/

		ParkingSlotsService service = new ParkingSlotsService();
		ParkingSlot ps =  ParkingSlotTransfer.transform(availableParkSlots);
		service.addParkingSlots(ps);
		
		
		return SUCCESS;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
		
	}

	public void setServletResponse(HttpServletResponse arg0) {
		this.response =arg0;
		
	}


}
